package com.example.pets.model.entities.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;

import com.example.pets.model.datasource.PetDataSource;
import com.example.pets.model.entities.Pet;
import com.example.pets.model.entities.Post;
import com.example.pets.model.entities.User;
import com.example.pets.model.entities.dao.ListConverter;
import com.example.pets.model.entities.dao.PetDao;
import com.example.pets.model.entities.dao.PostDao;
import com.example.pets.model.entities.dao.UserDao;

@Database(entities = {User.class, Pet.class, Post.class}, version = 3,exportSchema = false)
@TypeConverters(ListConverter.class)
public abstract class AppDatabase extends RoomDatabase {
    public abstract UserDao userDao();
    public abstract PetDao  petDao();
    public abstract PostDao postDao();
    private static volatile AppDatabase INSTANCE;

    public static AppDatabase getDatabase(final Context context) {
        if (INSTANCE == null) {
            synchronized (AppDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            AppDatabase.class, "database-name").build();
                }
            }
        }
        return INSTANCE;
    }
}
